const express = require('express');
const { authMiddleware, adminMiddleware } = require('../middlewares/auth.middleware');
const adminController = require('../controllers/admin.controller');

const router = express.Router();

// 仪表盘统计数据 - 添加中间件到每个路由
router.get('/stats', authMiddleware, adminMiddleware, adminController.getStats);
router.get('/stats/trend', authMiddleware, adminMiddleware, adminController.getTrendStats);
router.get('/activities', authMiddleware, adminMiddleware, adminController.getRecentActivities);

// 用户管理 - 添加中间件到每个路由
router.get('/users', authMiddleware, adminMiddleware, adminController.getUsers);
router.put('/users/:id/status', authMiddleware, adminMiddleware, adminController.updateUserStatus);
router.put('/users/:id/role', authMiddleware, adminMiddleware, adminController.updateUserRole);
router.delete('/users/:id', authMiddleware, adminMiddleware, adminController.deleteUser);
router.post('/users/:id/update', authMiddleware, adminMiddleware, adminController.updateUser);
router.post('/users/create', authMiddleware, adminMiddleware, adminController.updateUser);

// 视频管理 - 添加中间件到每个路由
router.get('/videos', authMiddleware, adminMiddleware, adminController.getVideos);
router.post('/videos', authMiddleware, adminMiddleware, adminController.createVideo);
router.put('/videos/:id', authMiddleware, adminMiddleware, adminController.updateVideo);
router.put('/videos/:id/status', authMiddleware, adminMiddleware, adminController.updateVideoStatus);
router.delete('/videos/:id', authMiddleware, adminMiddleware, adminController.deleteVideo);

// 帖子管理 - 添加中间件到每个路由
router.get('/posts', authMiddleware, adminMiddleware, adminController.getPosts);
router.post('/posts', authMiddleware, adminMiddleware, adminController.createPost);
router.put('/posts/:id', authMiddleware, adminMiddleware, adminController.updatePost);
router.put('/posts/:id/status', authMiddleware, adminMiddleware, adminController.updatePostStatus);
router.delete('/posts/:id', authMiddleware, adminMiddleware, adminController.deletePost);

// 评论管理 - 添加中间件到每个路由
router.get('/comments', authMiddleware, adminMiddleware, adminController.getComments);
router.put('/comments/:id/status', authMiddleware, adminMiddleware, adminController.updateCommentStatus);
router.patch('/comments/:id/status', authMiddleware, adminMiddleware, adminController.updateCommentStatus);
router.delete('/comments/:id', authMiddleware, adminMiddleware, adminController.deleteComment);
router.patch('/comments/status', authMiddleware, adminMiddleware, adminController.batchUpdateCommentsStatus);
router.delete('/comments', authMiddleware, adminMiddleware, adminController.batchDeleteComments);

// 分类管理 - 添加中间件到每个路由
router.get('/categories', authMiddleware, adminMiddleware, adminController.getCategories);
router.post('/categories', authMiddleware, adminMiddleware, adminController.createCategory);
router.put('/categories/:id', authMiddleware, adminMiddleware, adminController.updateCategory);
router.delete('/categories/:id', authMiddleware, adminMiddleware, adminController.deleteCategory);

// 系统设置
router.get('/settings', authMiddleware, adminMiddleware, adminController.getSettings);
router.put('/settings', authMiddleware, adminMiddleware, adminController.updateSettings);

module.exports = router;